#ifndef _SPRITE_MANAGER_H_
#define _SPRITE_MANAGER_H_

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <vector>
#include <queue>
#include "Unit.h"

using namespace sf;


class SpriteContainer {
    public:
        Sprite sprite;
        int order;
        SpriteContainer(Sprite &s, int o) {
            sprite = s;
            order = o;
        }

        bool operator < (const SpriteContainer &b) const {
            Vector2f aPos = sprite.GetPosition();
            Vector2f bPos = b.sprite.GetPosition();
            if ((int)aPos.y == (int)bPos.y) {
                // if y positions are equal, sort by original
                // rendering order
                return order > b.order;
            }
            else {
                // otherwise, sort by y positions
                return aPos.y > bPos.y;
            }
        }
};

class SpriteManager {
    private:
        std::priority_queue<SpriteContainer> sprites;
        int orderCounter;

    public:
        SpriteManager();
        ~SpriteManager();

        void Draw(Sprite &sprite);
        void Render(RenderWindow &app);
};

#endif
